﻿
using System ;
using System.Collections.Generic ;

using MskEdit.Sdk ;
using MskEdit.Dxf.Model ;


namespace MskEdit.Dxf.Backend
{
    internal static class DxfHeaderReader
    {
#region Internal operations
                        
        internal static DxfHeader TryRead( string[] allLines, ref int lineNo, DxfHeader fallbackHeader ) {
            
            int internalLineNo = lineNo ;

            if ( DxfLineReader.TryRead( "2", "HEADER", allLines, ref internalLineNo, null ) == null ) 
                return fallbackHeader ;
        
            DxfHeader dxfHeader = new DxfHeader( null, new SdkSubrange(0,0) ) ; // Dummy
            
            while ( internalLineNo < allLines.Length ) {
                            
                DxfVariable dxfVariable = DxfVariableReader.TryRead( allLines, ref internalLineNo, null ) ;
                if ( dxfVariable == null )
                    break ;

                dxfHeader.AddVariable( dxfVariable ) ;
                System.Diagnostics.Debug.WriteLine( dxfVariable ) ;
            }

            lineNo = internalLineNo ;
             
            return dxfHeader ;
        }
        
#endregion

    }
}
